<?php require_once('header.php');?>

<div style="width: 100%; height: 5% /*;margin-left: 3%; margin-right: 3%;*/">
	<div style="float: left"><a href="<?php echo base_url('uc/add');?>">添加用户</a></div>
	<div style="float: right">
		<form action="<?php echo base_url('firstPage/userList')?>" method="post">
			<input type="text" name="name"  placeholder=" 输入用户名"/>
			<input type="hidden" name="searchKey" value="1"/>
			<input type="submit" name="submit" class="btn btn-default" value="搜索"/>
		</form>
	</div>
</div>

<ul class="nav nav-tabs">
	<li role="presentation"><a href="<?php echo base_url('firstPage/listResult');?>">文章管理</a></li>
	<li role="presentation" class="active"><a href="<?php echo base_url('firstPage/userList');?>">用户管理</a></li>
</ul>
<?php if(!is_string($result)):?>
	<?php if(is_string($backInfo)):?>
		<div class="alert alert-warning alert-dismissible" role="alert">
			<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			<?php echo $backInfo;?>
		</div>
	<?php else:?>
	<?php endif;?>
	<table class="table">
		<thead>
			<tr>
				<th>#</th>
				<th>用户名</th>
				<th>性别</th>
				<th>生日</th>
				<th>角色</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody id="list">
		<?php foreach($result as $value):?>
			<tr>
				<td><?php echo $value['userId'];?></td>
				<td><?php echo $value['username'];?></td>
				<td><?php echo $value['sex'];?></td>
				<td><?php echo $value['birthday'];?></td>
				<td><?php echo $value['authority']==0?'普通会员':'管理员';?></td>
				<?php if($value['authority']==0):?>
				<td><a href="<?php echo base_url("uc/upOthers?id={$value['userId']}")?>">修改</a>
					<a href="<?php echo base_url("uc/del?id={$value['userId']}")?>" onclick="return confirm('确定删除?')?true:false;">删除</a>
				</td>
				<?php else:?><td></td><?php endif;?>
			</tr>
		<?php endforeach;?>
		</tbody>

	</table>

	<nav>
		<ul class="pagination">
			<?php echo isset($pag)?$pag:'';?>
		</ul>
	</nav>

	<br/>

	<?php else:?>
	<div class="alert alert-warning alert-dismissible" role="alert">
		<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		<strong>Warning!</strong> <?php echo $result;?>
	</div>
	<?php endif;?>

<script type="text/javascript">
	$("document").ready(function(){
		function clickBind()
		{
			$(".ajax_page").unbind('click').bind('click',function(event){
				var url = $(this).attr("href");
				var p   = url.charAt(url.length-1); // 获得页码
				if(p>1)
				{
					$.get(url,{},function(res){
						res = eval(res); // 格式化
						//$("body").html(res);
						$("#list").html(''); // 清空列表

						for(var x=0; x < res.length; ++x)
						{
							var txt = "<tr>";
							txt += "<td>"+
								res[x]['userId']
							+"</td>";
							txt += "<td>"+
								res[x]['username']
							+"</td>";
							txt += "<td>"+
								res[x]['sex']
							+"</td>";
							txt += "<td>"+
								res[x]['birthday']
							+"</td>";

							if(res[x]['authority']==0)
							{
								txt +="<td>普通会员</td>";
								if(res[x]['preAuthor']==1){
									txt += "<td>"+
									"<a href='"+res[x]['upURL']+"'>修改</a>"+" <a href='"+res[x]['delURL']+"'>删除</a>"
									+"</td>";
								}
							}else{
								txt +="<td>管理员</td>";
							}

							txt += "</tr>";
							$("#list").append(txt);
							$(".pagination").html(res[x]['pag']);
						}
						clickBind();
					});
					event.preventDefault();
				}
			});
		}
		clickBind();
	});

</script>

<?php include('foot.php');?>